package com.cd.servlet;

import cn.hutool.json.JSONUtil;
import com.cd.dao.ClassesDao;
import com.cd.entity.Classes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private ClassesDao dao = null;

	@Override
	public void init() throws ServletException {
		dao = new ClassesDao();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=utf-8");
		req.setCharacterEncoding("utf-8");
		List<Classes> classes = dao.findAll();
		String str = JSONUtil.toJsonStr(classes);
		resp.getWriter().write(str);
		resp.getWriter().flush();
	}
}
